package com.hellodoctor.profile;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;

import com.hellodoctor.slayer.model.Appointment;
import com.hellodoctor.slayer.model.Profile;
import com.hellodoctor.slayer.model.impl.AppointmentImpl;
import com.hellodoctor.slayer.model.impl.ProfileImpl;
import com.hellodoctor.slayer.service.AppointmentLocalServiceUtil;
import com.hellodoctor.slayer.service.ProfileLocalServiceUtil;
import com.hellodoctor.slayer.service.ProfileServiceUtil;
import com.hellodoctor.slayer.service.persistence.ProfilePersistence;
import com.hellodoctor.util.LConstants;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

/**
 * Portlet implementation class profile
 */
public class profile extends MVCPortlet {
	@Override
	public void init() throws PortletException {
		super.init();
		addProcessActionSuccessMessage = false;
	}
		
public void updateProfile(ActionRequest actionRequest,
		ActionResponse actionResponse) throws IOException, PortletException {
	User user = null;
	try {
		 user = PortalUtil.getUser(actionRequest);
	} catch (PortalException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SystemException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	int speciality,qualification,practicingSince=0;
	speciality=ParamUtil.getInteger(actionRequest, "speciality");
	qualification=ParamUtil.getInteger(actionRequest, "qualification");
	practicingSince=ParamUtil.getInteger(actionRequest, "practicingSince");
	
	
	Profile profile = new ProfileImpl();
	profile = ProfileLocalServiceUtil.getProfileByUserId(user.getUserId());
	profile.setSpeciality(speciality);
	profile.setQualification(qualification);
	profile.setPracticingSince(practicingSince);
	profile.setModifiedDate(new java.util.Date());
	try {
		profile = ProfileLocalServiceUtil.updateProfile(profile);
	} catch (SystemException e) {
		e.printStackTrace();
	}
	
}

public void cancelAppointment(ActionRequest actionRequest,
		ActionResponse actionResponse) throws IOException, PortletException {
	long appointmentId = ParamUtil.getLong(actionRequest, "appointmentId");
	Appointment appointmet = new AppointmentImpl();
	try {
		appointmet = AppointmentLocalServiceUtil.fetchAppointment(appointmentId);
		appointmet.setStatus(LConstants.Appointment_Status_CancelledByPatient);
		appointmet= AppointmentLocalServiceUtil.updateAppointment(appointmet);
	} catch (SystemException e) {
		e.printStackTrace();
	}
	
}

}
